<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="影院" prop="cinemaName">
        <el-input
          v-model="queryParams.cinemaName"
          placeholder="请输入影院"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="放映时间">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="dateRange"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="影厅名称" prop="hallName">
        <el-input
          v-model="queryParams.hallName"
          placeholder="请输入影厅名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="影片" prop="filmName">
        <el-input
          v-model="queryParams.filmName"
          placeholder="请输入影片"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['cinema:schedule:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['cinema:schedule:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['cinema:schedule:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cinema:schedule:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="scheduleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="影片" align="center" prop="filmName" />
      <el-table-column label="影院" align="center" prop="cinemaName" />
      <el-table-column label="放映开始时间" align="center" prop="showDateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.showDateTime, '{y}-{m}-{d}  {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="影厅名称" align="center" prop="hallName" />
      <el-table-column label="标准价" align="center" prop="ticketStandardPrice" />
      <el-table-column label="最低票价" align="center" prop="ticketLowestPrice" />
      <el-table-column label="网络代售费" align="center" prop="ticketFee" />
      <el-table-column label="网络代售费类型" align="center" prop="feeType" :formatter="feeTypeFormat" />
      <el-table-column label="截止售票时间" align="center" prop="stopSellingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.stopSellingTime, '{y}-{m}-{d}  {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="影片语言" align="center" prop="language" />
      <el-table-column label="影片时长" align="center" prop="duration" />
      <el-table-column label="影片视觉" align="center" prop="dimensional" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cinema:schedule:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="gotoScheduleAreaInfo(scope.row)"
            v-hasPermi="['cinema:scheduleAreaInfo:list']"
          >分区价格</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['cinema:schedule:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改影片排期对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="影院ID" prop="cinemaId">
          <el-input v-model="form.cinemaId" placeholder="请输入影院ID" />
        </el-form-item>
        <el-form-item label="排期编码" prop="scheduleId">
          <el-input v-model="form.scheduleId" placeholder="请输入排期编码" />
        </el-form-item>
        <el-form-item label="排期校验串" prop="scheduleKey">
          <el-input v-model="form.scheduleKey" placeholder="请输入排期校验串" />
        </el-form-item>
        <el-form-item label="影院内码" prop="cinemaLinkId">
          <el-input v-model="form.cinemaLinkId" placeholder="请输入影院内码" />
        </el-form-item>
        <el-form-item label="放映开始时间" prop="showDateTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.showDateTime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择放映开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="影厅编码" prop="hallCode">
          <el-input v-model="form.hallCode" placeholder="请输入影厅编码" />
        </el-form-item>
        <el-form-item label="影厅名称" prop="hallName">
          <el-input v-model="form.hallName" placeholder="请输入影厅名称" />
        </el-form-item>
        <el-form-item label="标准价" prop="ticketStandardPrice">
          <el-input v-model="form.ticketStandardPrice" placeholder="请输入标准价" />
        </el-form-item>
        <el-form-item label="最低票价" prop="ticketLowestPrice">
          <el-input v-model="form.ticketLowestPrice" placeholder="请输入最低票价" />
        </el-form-item>
        <el-form-item label="网络代售费" prop="ticketFee">
          <el-input v-model="form.ticketFee" placeholder="请输入网络代售费" />
        </el-form-item>
        <el-form-item label="网络代售费类型 ，order每张单计费，ticket每张票计费" prop="feeType">
          <el-select v-model="form.feeType" placeholder="请选择网络代售费类型 ，order每张单计费，ticket每张票计费">
            <el-option
              v-for="dict in feeTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="截止售票时间" prop="stopSellingTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.stopSellingTime"
            type="date"
            value-format="yyyy-MM-dd  HH:mm:ss"
            placeholder="选择截止售票时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开售标示">
          <el-radio-group v-model="form.saleStatus">
            <el-radio
              v-for="dict in saleStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="对应座位图版本编码" prop="seatVersion">
          <el-input v-model="form.seatVersion" placeholder="请输入对应座位图版本编码" />
        </el-form-item>
        <el-form-item label="是否明星场" prop="starsShowFlag">
          <el-input v-model="form.starsShowFlag" placeholder="请输入是否明星场" />
        </el-form-item>
        <el-form-item label="是否首映" prop="firstShowFlag">
          <el-input v-model="form.firstShowFlag" placeholder="请输入是否首映" />
        </el-form-item>
        <el-form-item label="场次自动开售时间" prop="saleOpendateTime">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.saleOpendateTime"
            type="date"
            value-format="yyyy-MM-dd  HH:mm:ss"
            placeholder="选择场次自动开售时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="影片编码" prop="filmCode">
          <el-input v-model="form.filmCode" placeholder="请输入影片编码" />
        </el-form-item>
        <el-form-item label="影片ID" prop="filmId">
          <el-input v-model="form.filmId" placeholder="请输入影片ID" />
        </el-form-item>
        <el-form-item label="影片语言" prop="language">
          <el-input v-model="form.language" placeholder="请输入影片语言" />
        </el-form-item>
        <el-form-item label="影片语言编码" prop="languageCode">
          <el-input v-model="form.languageCode" placeholder="请输入影片语言编码" />
        </el-form-item>
        <el-form-item label="影片时长" prop="duration">
          <el-input v-model="form.duration" placeholder="请输入影片时长" />
        </el-form-item>
        <el-form-item label="影片视觉" prop="dimensional">
          <el-input v-model="form.dimensional" placeholder="请输入影片视觉" />
        </el-form-item>
        <el-form-item label="影片版本编码" prop="dimensionalCode">
          <el-input v-model="form.dimensionalCode" placeholder="请输入影片版本编码" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSchedule, getSchedule, delSchedule, addSchedule, updateSchedule, exportSchedule } from "@/api/cinema/schedule";

export default {
  name: "Schedule",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 影片排期表格数据
      scheduleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 网络代售费类型 ，order每张单计费，ticket每张票计费字典
      feeTypeOptions: [],
      // 开售标示字典
      saleStatusOptions: [],
      // 是否明星场字典
      starsShowFlagOptions: [],
      // 是否首映字典
      firstShowFlagOptions: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cinemaName: null,
        showDateTime: null,
        endDateTime: null,
        hallName: null,
        filmName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("schedule_fee_type").then(response => {
      this.feeTypeOptions = response.data;
    });
    this.getDicts("schedule_sale_status").then(response => {
      this.saleStatusOptions = response.data;
    });
    this.getDicts("schedule_stars_show_flag").then(response => {
      this.starsShowFlagOptions = response.data;
    });
    this.getDicts("schedule_first_show_flag").then(response => {
      this.firstShowFlagOptions = response.data;
    });
  },
  methods: {
    /** 查询影片排期列表 */
    getList() {
      this.loading = true;
      listSchedule(this.setDateRange(this.queryParams,this.dateRange)).then(response => {
        this.scheduleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    setDateRange(params, dateRange){
        var search = params;
        search.showDateTime = null;
        search.endDateTime = null;
        if (null != dateRange && '' != dateRange) {
          search.showDateTime = dateRange[0];
          search.endDateTime = dateRange[1];
        }
        return search;
    },
    gotoScheduleAreaInfo(row){
      const id = row.id
      this.$router.push({path: "/scheduleM/scheduleAreaInfo",query:{scheduleId: id}})
    },
    // 网络代售费类型 ，order每张单计费，ticket每张票计费字典翻译
    feeTypeFormat(row, column) {
      return this.selectDictLabel(this.feeTypeOptions, row.feeType);
    },
    // 开售标示字典翻译
    saleStatusFormat(row, column) {
      return this.selectDictLabel(this.saleStatusOptions, row.saleStatus);
    },
    // 是否明星场字典翻译
    starsShowFlagFormat(row, column) {
      return this.selectDictLabel(this.starsShowFlagOptions, row.starsShowFlag);
    },
    // 是否首映字典翻译
    firstShowFlagFormat(row, column) {
      return this.selectDictLabel(this.firstShowFlagOptions, row.firstShowFlag);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cinemaId: null,
        scheduleId: null,
        scheduleKey: null,
        cinemaLinkId: null,
        showDateTime: null,
        hallCode: null,
        hallName: null,
        ticketStandardPrice: null,
        ticketLowestPrice: null,
        ticketFee: null,
        feeType: null,
        stopSellingTime: null,
        saleStatus: "0",
        seatVersion: null,
        starsShowFlag: null,
        firstShowFlag: null,
        saleOpendateTime: null,
        filmCode: null,
        filmId: null,
        language: null,
        languageCode: null,
        duration: null,
        dimensional: null,
        dimensionalCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.dateRange = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加影片排期";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSchedule(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改影片排期";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSchedule(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSchedule(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除影片排期编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delSchedule(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有影片排期数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportSchedule(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
